import java.sql.*;

public class Test {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //数据库URL
        String url = "jdbc:mysql://8.130.104.17:3306/lx";

        String user = "YCLJ";
        String password = "123456";

        Connection conn = null;

        // 加载和注册JDBC驱动
        Class.forName("com.mysql.cj.jdbc.Driver");

        // 建立数据库连接
        conn = DriverManager.getConnection(url, user, password);

        // 创建Statement对象
        Statement st = conn.createStatement();

        // 执行SQL语句
        String sql = "SELECT * FROM emp";
        ResultSet rs = st.executeQuery(sql);
        System.out.println("id" + "\t" + "workno" + "\t" + "name" + "\t" + "gender" + "\t" + "age" + "\t\t\t" + "idcard" + "\t" + "workaddress" + "\t" + "entrydate");
        while (rs.next()) {
            String id = rs.getString("id");
            String workno = rs.getString("workno");
            String name = rs.getString("name");
            String gender = rs.getString("gender");
            String age = rs.getString("age");
            String idcard = rs.getString("idcard");
            String workaddress = rs.getString("workaddress");
            String entrydate = rs.getString("entrydate");
            System.out.printf(id+"\t"+ workno+ "\t"+name+"\t\t"+ gender+"\t"+ age+ "\t"+idcard+ "\t"+workaddress+"\t"+ entrydate+"\n");
        }

    }
}
